using System;
using System.Linq;
using System.Collections.Generic;

using DemoApp.DataAccess;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.Data;

namespace DemoApp.BusinessLayer 
{
  public partial class FavoriteObjectRepository : 
    IFavoriteObjectRepository 
  {
    public IBusinessObjectCollection<IFavorite> RetrieveAll()
    {
      var query = new FavoriteLoadSettings();
      return Retrieve(query);
    }

    public IBusinessObjectCollection<IFavorite> Retrieve(FavoriteLoadSettings query)
    {
      query = FavoriteLoadSettings.FromFavoriteLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaFavoriteInfoCollection.GetFavoriteInfoCollection(query);
        return result;
      }
      else
      {
        var result = CslaFavoriteEditCollection.GetFavoriteEditCollection(query);
        return result;
      }
    }

    public IFavorite RetrieveOne(FavoriteLoadSettings query)
    {
      query = FavoriteLoadSettings.FromFavoriteLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaFavoriteInfoCollection.GetFavoriteInfoCollection(query);
        return result.FirstOrDefault<IFavorite>();
      }
      else
      {
        var result = CslaFavoriteEditCollection.GetFavoriteEditCollection(query);
        return result.FirstOrDefault<IFavorite>();
      }
    }

    public int Count()
    {
      return Count(null);
    }

    public int Count(FavoriteLoadSettings query)
    {
      query = FavoriteLoadSettings.FromFavoriteLoadSettings(query);
      return CslaFavoriteInfoCollection.GetCount(query);
    }

    public IFavorite New()
    {
      return CslaFavoriteEdit.New();
    }

    public void Save(IBusinessObjectCollection<IFavorite> collection)
    {
      throw new NotImplementedException();
    }

    public void Save(IFavorite obj)
    {
      throw new NotImplementedException();
    }
  }
}
